package task3;

import java.util.ArrayList;
import java.util.Scanner;

public class test5 {

    static Scanner input=new Scanner(System.in);
    static ArrayList<ArrayList<Integer>> outer=new ArrayList<>();
    static ArrayList<Integer> list;
    static MyQueue queue=new MyQueue();

    public static void main(String[] args) {

        int n= input.nextInt();
        int op;

        for(int i=0;i<n;i++){
            list=new ArrayList<>();
            op= input.nextInt();
            list.add(op);
            if(op==1){
                op= input.nextInt();
                list.add(op);
            }
            outer.add(list);
        }
        for(ArrayList<Integer> list:outer){
            progress(list);
        }
    }
    private static void progress(ArrayList<Integer> list){
        switch (list.get(0)){
            case 1:{
                queue.push(list.get(1));
            }break;
            case 2:{
                System.out.println(queue.size()>0?queue.pop():"Invalid");
            }break;
            case 3:{
                System.out.println(queue.size());
            }break;
        }
    }
}

class MyQueue{

    ArrayList<Integer> queue;

    public MyQueue(){
        queue=new ArrayList<>();
    }

    public void push(int x){//入队
        queue.add(x);
    }

    public int pop(){//出队
        int x=queue.get(0);
        queue.remove(0);
        return x;
    }

    public int size(){//求长度
        return queue.size();
    }
}